package com.dnjn.happiness.biz.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dnjn.happiness.biz.domain.Outlet;
import com.dnjn.happiness.biz.domain.vo.OutletExportBean;
import com.dnjn.happiness.biz.domain.vo.OutletVO;
import com.dnjn.happiness.biz.domain.vo.OutletWeekPublishInfoVO;
import com.dnjn.happiness.biz.domain.vo.OutletWeekRankingVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 解忧馆Mapper接口
 *
 * @author happiness
 * @date 2024-03-13
 */
public interface OutletMapper extends BaseMapper<Outlet> {

    Page<OutletVO> getPage(Page page, @Param("dto") Outlet outlet);

    @Select(" SELECT count(1) AS count,`week` FROM biz_outlet WHERE `year` = YEAR(NOW()) AND deleted = '0' GROUP BY `week` ORDER BY `week` ")
    List<OutletWeekPublishInfoVO> getWeekPublishInfo();

    @Select(" SELECT `week` FROM biz_outlet WHERE `year` = YEAR(NOW()) AND deleted = '0' GROUP BY `week` ORDER BY `week` ")
    List<String> getWeekList();

    @Select(" SELECT count(1) AS count FROM biz_outlet WHERE `year` = YEAR(NOW()) AND deleted = '0' AND outlet_status = #{status} AND `week` = #{week} ")
    Integer getValueByStatusAndWeek(@Param("week") String week, @Param("status") String status);

    @Select(" SELECT t1.number number,t1.user_id userId,u.nick_name nickName,u.avatar,u.sex FROM" +
            " (SELECT count(1) number,user_id FROM biz_outlet WHERE `week` = WEEK(NOW(),1) AND `year` = YEAR(NOW()) AND deleted = '0' GROUP BY user_id) t1 " +
            "LEFT JOIN sys_user u USING(user_id) WHERE u.del_flag = '0' ORDER BY number DESC LIMIT 0,20 ")
    List<OutletWeekRankingVO> getWeekRankingAgoTwenty();

    List<OutletWeekRankingVO> getWeekOutletValueAgoTwenty();

    List<OutletExportBean> getExportList(@Param("dto") Outlet outlet);

    @Select(" SELECT * FROM biz_outlet WHERE user_id = #{userId} AND is_reply = 'Y' and deleted = '0' ORDER BY outlet_time DESC LIMIT 1 ")
    Outlet getLastOutletByUserId(Long userId);

}
